import numpy as np
import matplotlib.pyplot as plt
import os

# define data directory
fname = 'exfig4e.npz'

# load npz file
data = np.load(fname, allow_pickle=True)
print(data.files)
B_up = data['B_up']
B_down = data['B_down']
Rxy_up = data['Rxy_up']
Rxy_down = data['Rxy_down']
B_lin = data['B_lin']
Rxy_asym = data['Rxy_asym']
Temperature = data['Temperature']
indices = data['indices']


# plot raw data
fig, ax = plt.subplots()
fig.suptitle('exfig4e raw data')
for i in indices:
    ax.plot(B_up[:,i], Rxy_up[:, i]/1e3, label='T = ' + str(Temperature[i]) + ' K')
    ax.plot(B_down[:,i], Rxy_down[:, i]/1e3, label='T = ' + str(Temperature[i]) + ' K')
ax.set_xlabel('$B$ (T)')
ax.set_ylabel('$R_{yx}$ raw')
ax.legend()
plt.show()

# plot processed data
fig, ax = plt.subplots()
fig.suptitle('exfig4e antisymmetrized data')
for i in indices:
    ax.plot(B_lin, Rxy_asym[:, i]/1e3, label='T = ' + str(Temperature[i]) + ' K')
    ax.plot(B_lin, -Rxy_asym[::-1, i]/1e3, label='T = ' + str(Temperature[i]) + ' K')
ax.set_xlabel('$B$ (T)')
ax.set_ylabel('$R_{yx}$ antisymmetrized (kOhm)')
ax.legend()
plt.show()